# -*- coding:utf-8 -*-
import web, models
from baseHandler import BaseHandler
from utils.decorator import render

class Contacts(BaseHandler):
    @render('contacts.html')
    def GET(self):
        contacts = models.Contact.getAllContacts()
        return {'title' : u'联系人列表', 'contacts' : contacts}

    @render(None, 'json')
    def POST(self):
        self.admin_requried()
        name = web.input().get('name')
        company = web.input().get('company')
        phone = web.input().get('phone')
        email = web.input().get('email')
        models.Contact.addContact(name, company, phone, email)


